package com.carl.controller;

import com.carl.model.Medal;
import com.carl.service.MedalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;


@Slf4j
@Controller
@RequestMapping("/medal")
@Api(value = "medal控制器", description = "奖牌常用API接口")
public class MedalController {

    @Autowired
    private MedalService medalService ;

    @Autowired
    private RestTemplate restTemplate;

    private String restURL ;

    @ResponseBody
    @PostMapping("/demoInfo")
    @ApiOperation(value = "微服务-奖牌信息" , notes = "测试", httpMethod = "POST")
    public Object demoMedalInfo(){
        log.info("$$$ 微服务调用接口 @@@");
        restURL = "http://127.0.0.1:8080/medal/50/info" ;
        return restTemplate.getForObject(restURL, Medal.class);
    }

    @ResponseBody
    @RequestMapping("/{id}/info")
    @ApiParam(name = "id",value = "50")
    @ApiOperation(value = "单个奖牌详情" , notes = "由唯一id查询相关信息", httpMethod = "GET")
    public Medal getMedalInfoById(@PathVariable("id") Long id) {
        return medalService.selectById(id);
    }

}
